<?php
/*
 * Aclass_time
 * 2010-12-03
 * http://www.abans.cn		abans@qq.com


 */
class Aclass_time{
	function  __construct($arr) {
	}
	
	/*时间加减函数*/
	function date_add($datetime,$number,$type=""){
		if(empty($type)){
			$row = strlen($datetime);
			switch ($row) {
				case "4": $type = 'Y'; break;
				case "7": $type = 'm'; break;
				case "10": $type = 'd'; break;
				case "13": $type = 'H'; break;
				case "16": $type = 'i'; break;
				case "19": $type = 's'; break;
			}
		}
		return $this->time_add(strtotime($datetime),$number,$type);
	}
	function time_add($time,$number,$type){
		$date_time_array = getdate($time);
		$hours = $date_time_array["hours"];
		$minutes = $date_time_array["minutes"];
		$seconds = $date_time_array["seconds"];
		$month = $date_time_array["mon"];
		$day = $date_time_array["mday"];
		$year = $date_time_array["year"];
		switch ($type) {
				case "Y": $year +=$number; break; //年
				case "q": $month +=($number*3); break; //季度
				case "m": $month +=$number; break; //月
				case "d": $day+=$number; break; //天
				case "w": $day+=($number*7); break; //周
				case "H": $hours+=$number; break; //小时
				case "n": $minutes+=$number; break; //分钟
				case "s": $seconds+=$number; break; //秒
		}
		$timestamp = mktime($hours ,$minutes, $seconds,$month ,$day, $year);
		return $timestamp;
	}

}

?>
